//
//  AllBtnCell.m
//  HubeiHotel
//
//  Created by LiBenCan on 17/11/27.
//  Copyright © 2017年 张露杰. All rights reserved.
//

#import "AllBtnCell.h"
#import "CanLab.h"
@implementation AllBtnCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}

- (void)loadDic:(NSDictionary *)dic Section:(NSInteger)section
{
    //移除视图
    for (UIView *view  in self.contentView.subviews) {
        [view removeFromSuperview];
    }
    _section = section;
    NSInteger num = 0;
    //循环创建按钮
    for (int i = 0;i < [[dic objectForKey:@"secondList"] count]; i++) {
        float x = 15*screenW_6 + (SCREENW-30*screenW_6)/4*(i%4);
        float y = 36*screenW_6 *(i/4);
        
        CanLab *btnlab = [[CanLab alloc]initWithFrame:CGRectMake(x, y,(SCREENW-27*screenW_6)/4,37*screenW_6) textAligment:1 font:14*screenW_6 textColor:@"#777777" text:[[[dic objectForKey:@"secondList"] objectAtIndex:i] objectForKey:@"name"]];
        btnlab.backgroundColor = [UIColor whiteColor];
        btnlab.layer.borderWidth = 0.5;
        btnlab.layer.borderColor = [[UIColor colorWithHexString:@"#dddddd"] CGColor];
        [self.contentView addSubview:btnlab];
        btnlab.userInteractionEnabled = YES;
        
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.frame = CGRectMake(x, y,(SCREENW-27*screenW_6)/4,37*screenW_6);
        [self.contentView addSubview:button];
        button.tag = num;
        [button addTarget:self action:@selector(choseButton:) forControlEvents:UIControlEventTouchUpInside];
        num++;
        _height = CGRectGetMaxY(button.frame) + 15*screenW_6;
    }
}

- (void)choseButton:(UIButton *)btn
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(button:Section:)]) {
        [self.delegate button:btn.tag Section:_section];
    }
}

- (CGFloat)height
{
    return _height;
}

+ (CGFloat)cellHeight:(NSDictionary *)data Section:(NSInteger)section
{
    AllBtnCell *cell = [[AllBtnCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"AllBtnCell"];
    [cell loadDic:data Section:section];
    return [cell height];
}

@end
